package com.ruoyi.project.warehouseSystem.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.warehouseSystem.domain.Component;
import com.ruoyi.project.warehouseSystem.service.IComponentService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 配件信息Controller
 * 
 * @author wangshuo
 * @date 2021-01-22
 */
@RestController
@RequestMapping("/warehouseSystem/component")
public class ComponentController extends BaseController
{
    @Autowired
    private IComponentService componentService;

    /**
     * 查询配件信息列表
     */
    @PreAuthorize("@ss.hasPermi('warehouseSystem:component:list')")
    @GetMapping("/list")
    public TableDataInfo list(Component component)
    {
        startPage();
        List<Component> list = componentService.selectComponentList(component);
        return getDataTable(list);
    }

    /**
     * 导出配件信息列表
     */
    @PreAuthorize("@ss.hasPermi('warehouseSystem:component:export')")
    @Log(title = "配件信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Component component)
    {
        List<Component> list = componentService.selectComponentList(component);
        ExcelUtil<Component> util = new ExcelUtil<Component>(Component.class);
        return util.exportExcel(list, "component");
    }

    /**
     * 获取配件信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouseSystem:component:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(componentService.selectComponentById(id));
    }

    /**
     * 新增配件信息
     */
    @PreAuthorize("@ss.hasPermi('warehouseSystem:component:add')")
    @Log(title = "配件信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Component component)
    {
        return toAjax(componentService.insertComponent(component));
    }

    /**
     * 修改配件信息
     */
    @PreAuthorize("@ss.hasPermi('warehouseSystem:component:edit')")
    @Log(title = "配件信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Component component)
    {
        return toAjax(componentService.updateComponent(component));
    }

    /**
     * 删除配件信息
     */
    @PreAuthorize("@ss.hasPermi('warehouseSystem:component:remove')")
    @Log(title = "配件信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(componentService.deleteComponentByIds(ids));
    }
}
